package io.framework.modules.hpinfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.framework.common.constant.Constant;
import io.framework.common.page.PageData;
import io.framework.common.service.impl.CrudServiceImpl;
import io.framework.common.utils.ConvertUtils;
import io.framework.modules.hpinfo.dao.VTHpglProjectinfoDao;
import io.framework.modules.hpinfo.dto.HpglProjectGoordInfoDTO;
import io.framework.modules.hpinfo.dto.VTHpglProjectinfoDTO;
import io.framework.modules.hpinfo.entity.VTHpglProjectinfoEntity;
import io.framework.modules.hpinfo.service.VTHpglProjectinfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 环境影响评价管理-环评建设项目信息
 *
 * @author Gujq email
 * @since 1.0.0 2020-03-19
 */
@Service
public class VTHpglProjectinfoServiceImpl extends CrudServiceImpl<VTHpglProjectinfoDao, VTHpglProjectinfoEntity, VTHpglProjectinfoDTO> implements VTHpglProjectinfoService {

    @Autowired
    private VTHpglProjectinfoDao projectinfoDao;

    @Override
    public QueryWrapper<VTHpglProjectinfoEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<VTHpglProjectinfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public List<Map<String, Object>> getAllInfoToSelect(Map<String, Object> params) {

        return baseDao.getAllInfoToSelect(params);
    }

    @Override
    public PageData<VTHpglProjectinfoDTO> pages(Map<String , Object> params){

        params = getParamsMap(params);

        IPage<VTHpglProjectinfoEntity> pages = getPage(params, Constant.CREATE_TIME, false);
        List<VTHpglProjectinfoEntity> list = baseDao.getList(params);
        return getPageData(list,pages.getTotal(),VTHpglProjectinfoDTO.class);
    }

    public Map<String, Object> getParamsMap(Map<String, Object> params){
        String regionName[],pffsName[];
        if(params.containsKey("regionName")){
            String name= params.get("regionName").toString().replaceAll("，",",");
            if(StringUtils.isNotBlank(name)){
                regionName = name.split(",");
                params.put("regionName",regionName);
            }
        }
        if(params.containsKey("pffsName")){
            String name= params.get("pffsName").toString().replaceAll("，",",");
            if(StringUtils.isNotBlank(name)){
                pffsName = name.split(",");
                params.put("pffsName",pffsName);
            }
        }
        return params;
    }

    @Override
    public List<VTHpglProjectinfoDTO> lists(Map<String , Object> params){
        params = getParamsMap(params);

        List<VTHpglProjectinfoEntity> list = baseDao.getList(params);

        return ConvertUtils.sourceToTarget(list,VTHpglProjectinfoDTO.class);
    }

    @Override
    public List<VTHpglProjectinfoDTO> getListCoordNotNull(Map<String , Object> params){

        params = getParamsMap(params);

        List<VTHpglProjectinfoEntity> list = baseDao.getListCoordNotNull(params);

        return ConvertUtils.sourceToTarget(list,VTHpglProjectinfoDTO.class);
    }

    @Override
    public List<HpglProjectGoordInfoDTO> getCoordList(Map<String , Object> params){

        params = getParamsMap(params);

        List<VTHpglProjectinfoEntity> list = projectinfoDao.getCoordList(params);

        return ConvertUtils.sourceToTarget(list,HpglProjectGoordInfoDTO.class);
    }

    @Override
    public List<Map<String,Object>> getSpjgList(){

        List<Map<String,Object>> mapList = projectinfoDao.getSpjgList();

        return mapList;
    }

    @Override
    public List<Map<String, Object>> statistics() {

        return baseDao.statistics();
    }

    @Override
    public List<Map<String, Object>> getHpglProjectCount(Map<String, Object> params) {

        List<Map<String, Object>> list = baseDao.getHpglProjectCount(params);

        return list;
    }

    @Override
    public Map<String, Object> getHbtzl(Map<String, Object> params) {

        Map<String, Object> list = baseDao.getHbtzl(params);

        return list;
    }

    @Override
    public List<Map<String, Object>> getHpglProjectTableCount(Map<String , Object> params){

        return baseDao.getHpglProjectTableCount(params);
    }

    @Override
    public List<Map<String, Object>> getHpglProjectTableCountApp(Map<String , Object> params){

        return baseDao.getHpglProjectTableCountApp(params);
    }

}